package com.smalls.newvideotwo.mvp.presenter;

import com.smalls.newvideotwo.mvp.base.BaseBeanResult;
import com.smalls.newvideotwo.mvp.base.BasePresenter;
import com.smalls.newvideotwo.mvp.beanResult.FilterContentResult;
import com.smalls.newvideotwo.mvp.http.constants.PortalErr;
import com.smalls.newvideotwo.mvp.http.constants.PortalErrUtil;
import com.smalls.newvideotwo.mvp.model.FilterContentModel;
import com.smalls.newvideotwo.mvp.model.modelInterface.IFilterContentModel;
import com.smalls.newvideotwo.mvp.view.IFilterContentView;
import com.smalls.newvideotwo.util.LogUtil;
import com.smalls.newvideotwo.utils.Constant;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.util.concurrent.TimeoutException;


public class FilterContentPresenter extends BasePresenter<IFilterContentView> implements BaseBeanResult.IFilterContent {
    private IFilterContentModel model = new FilterContentModel();
    private String country;
    private String tag;
    private String year;
    private static String TAG = Constant.baddcoolio2tag? Constant.TAGPREFIXSTR + "FilterContentPresenter":"FilterContentPresenter";
    public FilterContentPresenter(IFilterContentView view) {
        super(view);
    }

    public void filterContent(String country, String tag, String age) {
        this.model.filterContent(country,tag,age,this);
        this.country = country;
        this.tag = tag;
        this.year = age;
    }

    public void onNext(FilterContentResult bean) {
        if (bean == null || bean.getmAlbumList() == null || bean.getmAlbumList().size() == 0) {
            LogUtil.e(TAG, "\u663e\u793aDialog\u4fe1\u606fEB1");
            PortalErrUtil.getInstance().setErrCode(PortalErr.PORTAL_ROOT_COLUMN);
            ((IFilterContentView) this.view).getFilterContentFail(PortalErr.PORTAL_ROOT_COLUMN);
            return;
        }
        LogUtil.e(TAG, "获取数据成功 country="+country+" tag="+tag+" year="+year);
        ((IFilterContentView) this.view).getFilterContentSuc(bean, null);
    }

    public void onError(Throwable e) {
        String errCode = "";
        if ((e instanceof TimeoutException) || (e instanceof ConnectException) || (e instanceof SocketTimeoutException)) {
            LogUtil.e(TAG, "\u663e\u793aDialog\u4fe1\u606fEB2");
            errCode = PortalErr.STR_BOX_EPG_TIMEOUT_ERROR;
        } else {
            LogUtil.e(TAG, "\u663e\u793aDialog\u4fe1\u606fEB3");
            errCode = PortalErr.PORTAL_SYSTEM;
        }
        PortalErrUtil.getInstance().setErrCode(errCode);
        ((IFilterContentView) this.view).getFilterContentFail(errCode);
    }
}
